﻿CREATE PROCEDURE admin_lastTimeEntries AS
BEGIN
SELECT u.screenName, Convert(Varchar(10), MAX(tl.createDate),110) + ' '+ SUBSTRING(CONVERT(CHAR(19),MAX(tl.createDate),100),13,19)
 as lastTimeEntry from timeLog tl
inner join users u ON u.userId = tl.userId
inner join companyUser cu ON cu.userId = u.userId
WHERE cu.companyId = 10
GROUP BY u.screenName
order by 2 desc,1 
END